﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FinalText
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }
        private void Form1_Load(object sender, EventArgs e)
        {
        }
        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection sqlConnection = new SqlConnection("server =.;database=Blogs;uid=sa;pwd=123456;");
            var uid = textBox1.Text;
            var pwd = textBox2.Text;


            var sql = string.Format("select * from Users where Username='{0}'and Password='{1}'", uid, pwd);

            SqlCommand sqlCommand = new SqlCommand(sql);

            var dt = DbHelp.GetDataTable(sql);

            sqlConnection.Open();

            if (dt.Rows.Count == 1)
            {
                MessageBox.Show("登录成功");
                MainForm mainForm = new MainForm();
                mainForm.Show();
                this.Hide();
            }
              else  if (uid == ""&&pwd=="")
                    {
                        MessageBox.Show("账号密码不能为空");
                    }
                    else
                    {
                MessageBox.Show("登录失败");
                    }


                   

            

            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Register register = new Register();
            register.Show();
        }

        
    }
}
